#include <REGX52.H>
#include "Key.h"
#include "Nixie.h"
#include "Timer1.h"
#include "IR.h"

#define h0 0x16
#define h1 0x0C
#define h2 0x18
#define h3 0x5E

sbit motor = P1^0;

unsigned char Counter,Compare;
unsigned char Speed,Command;

void main()
{
	Timer1_Init();
	IR_Init();
	while(1)
	{
		if(IR_GetDataFlag())
		{
			Command=IR_GetCommand();
			if(Command==h0){Speed=0;}
			if(Command==h1){Speed=1;}
			if(Command==h2){Speed=2;}
			if(Command==h3){Speed=3;}

			if(Speed == 0){Compare=0;}
			if(Speed == 1){Compare=50;}
			if(Speed == 2){Compare=75;}
			if(Speed == 3){Compare=100;}
		}
		Nixie(1,Speed);
	}
}

//中断函数模板
void Timer1_Routine() interrupt 3
{
	TL1 = 0x9C;		//设置定时初值
	TH1 = 0xFF;		//设置定时初值
	Counter++;
	Counter%=100;
	if(Counter < Compare)
	{
		motor = 1;
	}
	else
	{
		motor = 0;
	}
}